<template>
    <div>
        <el-input
                placeholder="输入关键字进行过滤"
                v-model="filterText">
        </el-input>

        <el-tree
                class="filter-tree"
                :data="pigTree"
                :props="defaultProps"
                default-expand-all
                :filter-node-method="filterNode"
                ref="tree">
        </el-tree>
    </div>
</template>

<script>
import pigApi from '../../../api/pigApi';
    export default {
        name: 'PigTree',
        created() {
            this.getPigTree()
        },
        watch: {
            filterText(val) {
                this.$refs.tree.filter(val);
            }
        },

        methods: {
            filterNode(value, data) {
                if (!value) return true;
                return data.pigId.indexOf(value) !== -1;
            },
            getPigTree(){
                pigApi.getPigTree().then(res=>{
                    this.pigTree = res.data.pigTree
                    //todo 给节点添加其他信息
                })
            }
        },


        data() {
            return {
                filterText: '',
                pigTree: [],
                defaultProps: {
                    children: 'children',
                    label: 'pigId'
                }
            };
         }
        }
</script>

<style scoped>

</style>